package cc.higou.service;

import cc.higou.core.pojo.Sku;
import cc.higou.core.pojo.SuperPojo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 说明：
 * 库存信息的控制器
 *
 * @author:dongxing
 * @time:--
 */
@Controller
public class SkuController {

    private static final Logger LOGGER = LoggerFactory.getLogger(SkuController.class);
    @Autowired
    private SkuService skuService;

    //查询当前商品的库存
    @RequestMapping(value = "/console/sku/list.do")
    public String centerShowSkuList(Long productId, Model model) {
        LOGGER.info("centerShowSkuList开始执行了");
        //查询当前的商品的库存
        List<SuperPojo> skuList = skuService.findSkuByProductId(productId);
        LOGGER.info("SkuController类中的centerShowSkuList方法的返回值为：" + skuList);
        model.addAttribute("skuList", skuList);
        return "sku/list";
    }

    //更新库存信息
    @RequestMapping(value = "/console/sku/doUpdate.do")
    @ResponseBody
    public Map<String,Object> centerUpdateSku(Sku sku) {
        LOGGER.info("SkuController类中的centerUpdateSku开始执行了{}{}");
        //执行更新的操作
        Integer update = skuService.update(sku);
        Map<String, Object> map = new HashMap<>();
        if (update!=0) {
            map.put("su", "更新数据成功");
        }else{
            map.put("su", "更新数据失败");
        }
        return map;
    }

}
